package dsk.demo.product.controller.automarket;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dsk.demo.common.utils.R;
import dsk.demo.product.entity.AutoSendMailConfigEntity;
import dsk.demo.product.service.AutoSendMailConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("autoSendMailConfig")
public class AutoSendMailConfigController {

    @Autowired
    private AutoSendMailConfigService autoSendMailConfigService;

    /**
     * 获取所有状态正常的 配置
     *
     * @return
     */
    @GetMapping("/list")
    public R list() {
        QueryWrapper<AutoSendMailConfigEntity> query = new QueryWrapper<>();
        query.ne("status", "2");
        List<AutoSendMailConfigEntity> list = autoSendMailConfigService.list(query);
        System.out.println(list);
        return R.ok().put("data", list);
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable Long id) {
        AutoSendMailConfigEntity entity = autoSendMailConfigService.getById(id);
        return R.ok().put("data", entity);
    }

    @PostMapping("/saveOrUpdate")
    public R save(@RequestBody AutoSendMailConfigEntity entity) {
        if (StrUtil.isBlank(entity.getStatus())) {
            entity.setStatus("0");
        }
        autoSendMailConfigService.saveOrUpdate(entity);
        return R.ok();
    }

    @PostMapping("/delete/{id}")
    public R save(@PathVariable Long id) {
        autoSendMailConfigService.removeById(id);
        return R.ok();
    }

}
